var express = require('express');
var app = express();
var util    = require('util');
const fs = require('fs');
const port = 3001

var logPath = 'log.log'
var logFile = fs.createWriteStream(logPath, { flags: 'a' })

console.log = function() {
  logFile.write(util.format.apply(null, arguments) + '\n')
  process.stdout.write(util.format.apply(null, arguments) + '\n')
}

console.error = function() {
  logFile.write(util.format.apply(null, arguments) + '\n')
  process.stderr.write(util.format.apply(null, arguments) + '\n')
}

app.get('/', function(req, res){
  res.send('hello world');
});

app.get('/1', function(req, res){
  res.redirect(301, 'https://www.baidu.com');
});

app.get('/1', function(req, res){
  res.redirect(301, 'https://www.baidu.com');
});

app.listen(port, () => console.log(`Example app listening on port ${port}!`))